package com.eascs.workflow.controller;

import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.text.Format;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

import javax.inject.Inject;

import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import org.dom4j.Document;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.dubbo.config.annotation.Reference;
import com.eascs.admin.common.utils.ComConstants;
import com.eascs.admin.o2o.backFees.entity.O2oBackFeesEntity;
import com.eascs.admin.o2o.backFees.service.O2oBackFeesService;
import com.eascs.admin.o2o.backfee.entity.O2OComBackFee;
import com.eascs.admin.o2o.backfee.entity.OaBackFeeEntity;
import com.eascs.admin.o2o.backfee.service.O2OComBankFeeService;
import com.eascs.admin.o2o.credit.entity.CreditReport;
import com.eascs.admin.o2o.credit.service.CreditReportService;
import com.eascs.admin.o2o.detail.service.OaLoanapplyDetailService;
import com.eascs.admin.o2o.enterpriseZX.entity.O2oEnterpriseZxEntity;
import com.eascs.admin.o2o.enterpriseZX.service.O2oEnterpriseZxService;
import com.eascs.admin.o2o.internal.entity.LoanapplyExpand;
import com.eascs.admin.o2o.internal.entity.LoanapplyExpandDetail;
import com.eascs.admin.o2o.internal.entity.OaDeposit;
import com.eascs.admin.o2o.internal.service.LoanapplyExpandDetailService;
import com.eascs.admin.o2o.internal.service.LoanapplyExpandService;
import com.eascs.admin.o2o.internal.util.StatusContexts;
import com.eascs.admin.o2o.loan.action.O2oBankInfoForm;
import com.eascs.admin.o2o.loan.action.O2oContractForm;
import com.eascs.admin.o2o.loan.entity.O2oBankInfoEntity;
import com.eascs.admin.o2o.loan.entity.O2oLoanUserEntity;
import com.eascs.admin.o2o.loan.entity.O2oLoanapplyEntity;
import com.eascs.admin.o2o.loan.entity.O2oSDEntity;
import com.eascs.admin.o2o.loan.service.O2oLoanUserService;
import com.eascs.admin.o2o.loan.service.O2oLoanapplyService;
import com.eascs.admin.o2o.loan.service.O2oSdService;
import com.eascs.admin.o2o.loan.utils.BankRate;
import com.eascs.admin.o2o.loanAccount.entity.O2oCollectFee;
import com.eascs.admin.o2o.loanAccount.service.IO2oCollectFeesService;
import com.eascs.admin.o2o.loanAccount.vo.O2oCollectFeesVo;
import com.eascs.admin.o2o.o2ozx.serviceimpl.O2oLoadUserZxServiceImpl;
import com.eascs.admin.o2o.o2ozx.serviceimpl.O2oZxServiceImpl;
import com.eascs.admin.o2o.specialInterview.entity.O2OSpecialInterview;
import com.eascs.admin.o2o.specialInterview.service.O2OSpecialInterviewService;
import com.eascs.admin.o2o.zx.entity.O2oLoanUserEntityZx;
import com.eascs.admin.o2o.zx.entity.O2oZxEntity;
import com.eascs.afterloan.entity.AdvancedPayment;
import com.eascs.afterloan.form.AdvanceSettleForm;
import com.eascs.afterloan.service.AdvanceSettleService;
import com.eascs.app.dao.PageResult;
import com.eascs.app.log.Logger;
import com.eascs.app.log.LoggerFactory;
import com.eascs.app.log.TraceLoggerConfig;
import com.eascs.bankAccount.BankAccountService;
import com.eascs.common.util.DateUtils;
import com.eascs.common.util.StringUtil;
import com.eascs.common.util.UrlUtil;
import com.eascs.crm.common.custnew.service.CustomerService;
import com.eascs.crm.common.service.ICustomerInfoService;
import com.eascs.crm.nsEditDetail.service.CarInfoService;
import com.eascs.crm.nsEditDetail.service.HouseInfoService;
import com.eascs.crm.nsEditDetail.service.OtherInfoService;
import com.eascs.datalist.entity.O2oDataListEntity;
import com.eascs.datalist.service.O2oDataListService;
import com.eascs.file.FileTypeConstants;
import com.eascs.loan.entity.O2oBankLoanData;
import com.eascs.loan.form.O2oLoanForm;
import com.eascs.loan.form.O2oPaymentsForm;
import com.eascs.loan.service.O2oLoanService;
import com.eascs.loan.service.O2oPaymentsService;
import com.eascs.paymentdetail.entity.O2oTransferAccount;
import com.eascs.paymentdetail.service.O2oTransferAccountService;
import com.eascs.paymentdetail.vo.O2oTransferAccountVo;
import com.eascs.site.controller.BaseRestController;
import com.eascs.site.page.PaginationInfo;
import com.eascs.site.page.SelectDataOption;
import com.eascs.site.view.HtmlRestResult;
import com.eascs.site.view.ViewContext;
import com.eascs.site.view.button.AjaxButton;
import com.eascs.site.view.button.AjaxConfirmButton;
import com.eascs.site.view.button.Button;
import com.eascs.site.view.button.ButtonHelper;
import com.eascs.workflow.form.ComBackFeeWorkForm;
import com.eascs.workflow.form.CreditForm;
import com.eascs.workflow.form.MQZBSBYHFrom;
import com.eascs.workflow.form.O2OZXZBQRForm;
import com.eascs.workflow.form.SDForm;
import com.eascs.workflow.form.ZXPTCWForm;
import com.eascs.workflow.form.ZXSSYHForm;
import com.eascs.workflow.service.TranDepositSevice;
import com.eascs.workflow.service.ZxResolveService;
import com.eascs.workflow.util.CreditTransforCreditFrom;

@RestController
public class WorkFlowRestController extends BaseRestController {
	private static Logger logger = LoggerFactory.getLogger(WorkFlowRestController.class);
	@Autowired
	private O2oLoanapplyService o2oLoanapplyService;
	@Autowired
	private LoanapplyExpandService loanapplyExpandService;
	@Reference
	ICustomerInfoService iCustomerInfoService;
	@Autowired
	private O2oDataListService o2oDataListService;
	@Autowired
	private O2oSdService o2oSdService;
	@Autowired
	private O2oPaymentsService o2oPaymentsService;
	@Value("${sd.url}")
	private String sdUrl;
	@Autowired
	private O2oLoanService loanService;
	@Autowired
	private O2oLoanUserService o2oLoanUserService;
	@Autowired
	private O2OComBankFeeService o2OComBankFeeService;
	@Autowired
	private CreditReportService creditReportService;
	@Autowired
	private O2OComBankFeeService o2oComBankFeeService;
	@Autowired
	private LoanapplyExpandDetailService loanapplyExpandDetailService;
	@Autowired
	private OaLoanapplyDetailService oaloanapplyDetailService;
	@Autowired
	private ZxResolveService zxResolveService;
//	@Autowired
//	private TranDepositSevice tranDepositSevice;
	@Autowired
	AdvanceSettleService advanceSettleService;
	@Autowired
	private TranDepositSevice tranDepositSevice;
	@Autowired
	private O2OSpecialInterviewService o2OSpecialInterviewService;
	@Autowired
	private O2oTransferAccountService  o2oTransferAccountService;
	@Autowired
	private BankAccountService bankAccountService;
	
	@Autowired
	private O2oZxServiceImpl o2oZxServiceImpl;
	@Autowired
	private O2oLoadUserZxServiceImpl o2oLoadUserZxServiceImpl;
	
	@Autowired
	private O2oEnterpriseZxService o2oEnterpriseZxService;
	
	@Autowired
	O2oBackFeesService o2oBackFeesService;
	
	
	@Inject
	HouseInfoService houseInfoService;
	@Inject
	CarInfoService  carInfoService;
	@Inject
	OtherInfoService otherInfoService;
	@Reference
	CustomerService customerService;
	@Autowired
	IO2oCollectFeesService o2oCollectFeesService;
	
	/**
	 * 征信动态表单---平台财务
	 * 
	 * @param zXPTCWForm
	 * @return
	 */
	@RequestMapping(value = "/workflowcheck/zx_ptcw_view", method = RequestMethod.GET)
	public HtmlRestResult ptcw(ZXPTCWForm zXPTCWForm) {
		logger.info("征信平台财务接收zXPTCWForm：{}", zXPTCWForm.toString());
		ViewContext.put("zXPTCWForm", zXPTCWForm);
		return HtmlRestResult.html("workflowcheck/zx_ptcw");
	}

	/**
	 * 异步加载 征信表单
	 * 
	 * @param zXPTCWForm
	 * @return
	 */
	@RequestMapping(value = "/workflowcheck/ajaxPtcw", method = RequestMethod.GET)
	public HtmlRestResult ajaxPtcw(ZXPTCWForm zXPTCWForm) {
		logger.info("征信平台财务接收zXPTCWForm：{}", zXPTCWForm.toString());
		O2oLoanapplyEntity loanEntity = o2oLoanapplyService.findById(zXPTCWForm.getReferId());
		O2oSDEntity sdEntity = o2oSdService.getById(zXPTCWForm.getReferId());
		if (sdEntity == null) {
			O2oSDEntity o2osd = querySd(loanEntity.getCustomerCode(), zXPTCWForm.getReferId(),loanEntity.getCustomerNo());
			ViewContext.put("o2oSd", o2osd);
		} else {
			ViewContext.put("o2oSd", sdEntity);
		}
		O2oLoanapplyEntity loanapplyEntity = o2oLoanapplyService.findById(zXPTCWForm.getReferId());
		if (null != loanapplyEntity) {
			SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
			zXPTCWForm = new ZXPTCWForm();
			zXPTCWForm.setLoanapplyno(loanapplyEntity.getLoanapplyNo());
			zXPTCWForm.setReferId(loanapplyEntity.getLoanapplyNo());
			if (null != loanEntity.getEaCooperationDate())
			zXPTCWForm.setEaTime(format.format(loanapplyEntity.getEaCooperationDate()));
			zXPTCWForm.setEaStockNum(loanapplyEntity.getEaStockNum());
			zXPTCWForm.setTakeAvgAmount(loanapplyEntity.getEaPurchaseamount());
			zXPTCWForm.setArrearsAmountTotal(loanapplyEntity.getEaStockBorrowing());
			zXPTCWForm.setPaymentAvgAmount(loanapplyEntity.getEaReturnedAmount());
			zXPTCWForm.setCustomerSalesamount(loanapplyEntity.getCustomerSalesamount());
			zXPTCWForm.setZxRemark(loanapplyEntity.getZxRemark());
		}
		ViewContext.put("zXPTCWForm", zXPTCWForm);
		return HtmlRestResult.html("workflowcheck/ajxa_ptcw");
	}

	/**
	 * 上传其他附件 公用
	 * 
	 * @param zXSSYHForm
	 * @return
	 */
	@RequestMapping(value = "/workflowcheck/uploadOth", method = RequestMethod.GET)
	public HtmlRestResult uploadOth(ZXPTCWForm zXSSYHForm) {
		ViewContext.put("loanapplyNo", zXSSYHForm.getReferId());
		return HtmlRestResult.html("workflowcheck/upload_button");
	}

	
	/**
	 * 企业征信--动态表单
	 * 
	 * @param referId
	 * @return
	 */
	@RequestMapping(value = "/workflowcheck/newQYzx", method = RequestMethod.GET)
	public HtmlRestResult newQYzx(O2OZXZBQRForm o2OZXZBQRForm) {
		logger.info("企业征信：", o2OZXZBQRForm.toString());
		
		O2oEnterpriseZxEntity o2oEnterpriseZxEntity  = o2oEnterpriseZxService.getEntityById(o2OZXZBQRForm.getReferId());
		
		List<O2oDataListEntity> dataList = o2oDataListService.findByEntityList(o2OZXZBQRForm.getReferId());
		O2oDataListEntity ZXBGDATAEntity = null;
		for (int i = 0; i < dataList.size(); i++) {
			O2oDataListEntity entity = dataList.get(i);
			if (entity.getDatalistCode().equals(FileTypeConstants.ENTERPRISE_ZX_IDCARD)) {
				ZXBGDATAEntity = entity;
			} 
		}
		
		ViewContext.put("o2OZXZBQRForm", o2OZXZBQRForm);
		ViewContext.put("o2oEnterprise", o2oEnterpriseZxEntity);
		ViewContext.put("ZXBGDATAEntity", ZXBGDATAEntity);
		
		return HtmlRestResult.html("workflowcheck/newQYzx_zbzxqr");
		
	}
	
	
	/**
	 * 企业征信--	总部征信送审 2动态表单  浦发银行企业征信中征码
	 * 
	 * @param referId
	 * @return
	 */
	@RequestMapping(value = "/workflowcheck/newQYzx2", method = RequestMethod.GET)
	public HtmlRestResult newQYzx2(O2OZXZBQRForm o2OZXZBQRForm) {
		logger.info("企业征信：", o2OZXZBQRForm.toString());
		
		List<O2oDataListEntity> dataList = o2oDataListService.findByEntityList(o2OZXZBQRForm.getReferId());
		O2oDataListEntity ZXBGDATAEntity = null;
		for (int i = 0; i < dataList.size(); i++) {
			O2oDataListEntity entity = dataList.get(i);
			if (entity.getDatalistCode().equals(FileTypeConstants.ENTERPRISE_ZX_PFZXZZM)) {
				ZXBGDATAEntity = entity;
			} 
		}
		
		ViewContext.put("ZXBGDATAEntity", ZXBGDATAEntity);
		ViewContext.put("o2OZXZBQRForm", o2OZXZBQRForm);
		return HtmlRestResult.html("workflowcheck/newQYzx_zbzxqr2");
	}
	
	
	/**
	 * 企业征信--	总部征信送审 5动态表单  企业征信授权书（有中征码）
	 * 
	 * @param referId
	 * @return
	 */
	@RequestMapping(value = "/workflowcheck/newQYzx5", method = RequestMethod.GET)
	public HtmlRestResult newQYzx5(O2OZXZBQRForm o2OZXZBQRForm) {
		logger.info("企业征信：", o2OZXZBQRForm.toString());
		
		List<O2oDataListEntity> dataList = o2oDataListService.findByEntityList(o2OZXZBQRForm.getReferId());
		O2oDataListEntity ZXBGDATAEntity = null;
		for (int i = 0; i < dataList.size(); i++) {
			O2oDataListEntity entity = dataList.get(i);
			if (entity.getDatalistCode().equals(FileTypeConstants.ENTERPRISE_ZX_PFZXSQS)) {
				ZXBGDATAEntity = entity;
			} 
		}
		
		ViewContext.put("ZXBGDATAEntity", ZXBGDATAEntity);
		ViewContext.put("o2OZXZBQRForm", o2OZXZBQRForm);
		return HtmlRestResult.html("workflowcheck/newQYzx_zbzxqr5");
	}
	
	/**
	 * 新征信【总部征信确认】--动态表单
	 * 
	 * @param referId
	 * @return
	 */
	@RequestMapping(value = "/workflowcheck/newzx", method = RequestMethod.GET)
	public HtmlRestResult newzx(O2OZXZBQRForm o2OZXZBQRForm) {
		logger.info("新征信附件，附件时间：", o2OZXZBQRForm.toString());
		
		O2oZxEntity o2oZxEntity  = o2oZxServiceImpl.getEntityById(o2OZXZBQRForm.getReferId());
		
		O2oLoanUserEntityZx o2oLoanUserEntityZx = o2oLoadUserZxServiceImpl.getEntityByZxNo(o2OZXZBQRForm.getReferId());
		
		List<O2oDataListEntity> dataList = o2oDataListService.findByEntityList(o2OZXZBQRForm.getReferId());
		O2oDataListEntity ZXBGDATAEntity = null;
		O2oDataListEntity WarrantZXBGDATAEntity = null;
		for (int i = 0; i < dataList.size(); i++) {
			O2oDataListEntity entity = dataList.get(i);
			if (entity.getDatalistCode().equals(FileTypeConstants.DALIST_TYPE_ZXBGDATA)) {
				ZXBGDATAEntity = entity;
			} 
			if(FileTypeConstants.DALIST_TYPE_Warrant_ZXBGDATA.equals(entity.getDatalistCode())){
				WarrantZXBGDATAEntity = entity;
			}
		}
		
		ViewContext.put("o2OZXZBQRForm", o2OZXZBQRForm);
		
		ViewContext.put("o2oZxEntity", o2oZxEntity);
		
		ViewContext.put("WarrantZXBGDATAEntity", WarrantZXBGDATAEntity);
		
		ViewContext.put("ZXBGDATAEntity", ZXBGDATAEntity);
		
		ViewContext.put("o2oLoanUserEntityZx", o2oLoanUserEntityZx);
		return HtmlRestResult.html("workflowcheck/newzx_zbzxqr");
		
	}
	
	/**
	 * @Description:
	 *               <p>
	 *               新征信【总部征信送审】--动态表单--编辑中行送审数据
	 *               </p>
	 * @author LMX
	 * @date 2018年1月9日 上午11:25:28
	 * @version V1.0
	 * @param o2OZXZBQRForm
	 * @return
	 */
	@RequestMapping(value = "/workflowcheck/newzx_BcSsData", method = RequestMethod.GET)
	public HtmlRestResult newzx_BcSsData(O2OZXZBQRForm o2OZXZBQRForm) {
		logger.info("新征信附件，附件时间：", o2OZXZBQRForm.toString());
		
		O2oZxEntity o2oZxEntity  = o2oZxServiceImpl.getEntityById(o2OZXZBQRForm.getReferId());
		ViewContext.put("o2OZXZBQRForm", o2OZXZBQRForm);
		ViewContext.put("o2oZxEntity", o2oZxEntity);

		return HtmlRestResult.html("workflowcheck/newzx_BcSsData_update");
	}
	
	/**
	 * 征信--动态表单（送审银行-总部征信送审）
	 * 
	 * @param referId
	 * @return
	 */
	@RequestMapping(value = "/workflowcheck/zx", method = RequestMethod.GET)
	public HtmlRestResult list(ZXPTCWForm zXSSYHForm) {
		logger.info("征信送审银行和附件，接收ZXPTCWForm：", zXSSYHForm.toString());
		O2oLoanapplyEntity loanEntity = o2oLoanapplyService.findById(zXSSYHForm.getReferId());
	
		if (!StringUtil.isNull(loanEntity.getBankType())) {
			zXSSYHForm.setBanktype(loanEntity.getBankType());
		}
		
		ViewContext.put("zXSSYHForm", zXSSYHForm);
		return HtmlRestResult.html("workflowcheck/zx");
	}
	
	
	/**
	 * 征信--动态表单-(总部征信确认)
	 * 
	 * @param referId
	 * @return
	 */
	@RequestMapping(value = "/workflowcheck/zxqr", method = RequestMethod.GET)
	public HtmlRestResult zxqr(ZXPTCWForm zXSSYHForm) {
		logger.info("征信送审银行和附件，接收ZXPTCWForm：{}", zXSSYHForm.toString());
		O2oLoanapplyEntity loanEntity = o2oLoanapplyService.findById(zXSSYHForm.getReferId());
		List<O2oDataListEntity> dataList = o2oDataListService.findByEntityList(zXSSYHForm.getReferId());
		O2oDataListEntity payEntity = null;
		O2oDataListEntity materEntity = null;
		if (!StringUtil.isNull(loanEntity.getBankType())) {
			zXSSYHForm.setBanktype(loanEntity.getBankType());
		}
		for (int i = 0; i < dataList.size(); i++) {
			O2oDataListEntity entity = dataList.get(i);
			if (entity.getDatalistCode().equals(FileTypeConstants.DALIST_TYPE_ZXBGDATA)) {
				payEntity = entity;
			} else if (entity.getDatalistCode().equals(FileTypeConstants.DALIST_TYPE_ZXMATE)) {
				materEntity = entity;
			}
		}
		O2oLoanUserEntity  userEntity=o2oLoanUserService.findSpouseId(loanEntity.getLoanId(), loanEntity.getLoanapplyNo());
		logger.info("征信送审银行和附件，查询用户配偶：{}", userEntity);
		if (userEntity != null) {
			ViewContext.put("mater", userEntity);
		}
		ViewContext.put("payEntity", payEntity);
		ViewContext.put("materEntity", materEntity);
		ViewContext.put("zXSSYHForm", zXSSYHForm);
		return HtmlRestResult.html("workflowcheck/zxqr");
	}


	/**
	 * @Title: showTQHKSsyh
	 * @Description: 提前还款
	 * @author 张庆奇
	 * @param zXSSYHForm
	 * @return
	 * @return HtmlRestResult
	 * @throws
	 * @date 2017年2月21日 上午10:47:04
	 */
	@RequestMapping(value = "/workflowcheck/tqhk_ssyh", method = RequestMethod.GET)
	public HtmlRestResult showTQHKSsyh(AdvanceSettleForm advanceSettleForm) {
		logger.info("征信 总部初审和复审动态表单，接收ZXPTCWForm：", advanceSettleForm.toString());
		AdvancedPayment advancedPayment = advanceSettleService.queryEntity(advanceSettleForm.getReferId(), null);
		if(advancedPayment.getSettleDate()!=null){
			advanceSettleForm.setSettleDate(DateUtils.formateStandDate(advancedPayment.getSettleDate()));
		}
	
		ViewContext.put("advanceSettleForm", advanceSettleForm);
		return HtmlRestResult.html("workflowcheck/tqhk_ssyh");
	}
	
	/**
	 * 征信 总部初审和复审动态表单
	 * 
	 * @param zXSSYHForm
	 * @return
	 */
	@RequestMapping(value = "/workflowcheck/zx_ssyh", method = RequestMethod.GET)
	public HtmlRestResult showZxSsyh(ZXPTCWForm zXSSYHForm) {
		logger.info("征信 总部初审和复审动态表单，接收ZXPTCWForm：", zXSSYHForm.toString());
		O2oLoanapplyEntity loanEntity = o2oLoanapplyService.findById(zXSSYHForm.getReferId());
		if (!StringUtil.isNull(loanEntity.getBankType())) {
			zXSSYHForm.setBanktype(loanEntity.getBankType());
		}
		ViewContext.put("zXSSYHForm", zXSSYHForm);
		return HtmlRestResult.html("workflowcheck/zx_ssyh");
	}

	/**
	 * 征信 总部初审和复审动态表单 AJAX
	 * 
	 * @param zXSSYHForm
	 * @return
	 */
	@RequestMapping(value = "/workflowcheck/zx_ajax")
	public HtmlRestResult showZxAjax(ZXPTCWForm zXSSYHForm) {
		O2oLoanapplyEntity loanEntity = o2oLoanapplyService.findById(zXSSYHForm.getReferId());
		O2oLoanUserEntity userEntity = o2oLoanUserService.findSpouseId(loanEntity.getLoanId(), zXSSYHForm.getReferId());
		if (!StringUtil.isNull(loanEntity.getBankType())) {
			zXSSYHForm.setBanktype(loanEntity.getBankType());
		}
		CreditForm creditForm = new CreditForm();
		CreditReport creditReport = creditReportService.queryLoanapplyNo(zXSSYHForm.getReferId(),
				String.valueOf(StatusContexts.O2O_ZERO));
		if (creditReport != null) {
			// 查询配偶 征信信息
			CreditReport materCredit = creditReportService.queryLoanapplyNo(zXSSYHForm.getReferId(),
					String.valueOf(creditReport.getId()));
			if (materCredit != null) {
				CreditTransforCreditFrom.CreditTransToForm(creditForm, creditReport, materCredit);
				creditForm.setIds(materCredit.getId());
				creditForm.setParentIds(materCredit.getParentId());
			} else {
				CreditTransforCreditFrom.CreditTransToForm(creditForm, creditReport, null);
			}
		}
		ViewContext.put("loanEntity", loanEntity);
		ViewContext.put("userEntity", userEntity);
		ViewContext.put("creditForm", creditForm);
		ViewContext.put("zXSSYHForm", zXSSYHForm);
		return HtmlRestResult.html("workflowcheck/zx_ajax");
	}
	/**
	 * 征信接口 审批页面
	 * 
	 * @param zXSSYHForm
	 * @return
	 */
	@RequestMapping(value = "/workflowcheck/zx_view")
	public HtmlRestResult showZxView(ZXPTCWForm zXSSYHForm) {
		O2oLoanapplyEntity loanEntity = o2oLoanapplyService.findById(zXSSYHForm.getReferId());
		O2oLoanUserEntity userEntity = o2oLoanUserService.findSpouseId(loanEntity.getLoanId(), zXSSYHForm.getReferId());
		if (!StringUtil.isNull(loanEntity.getBankType())) {
			zXSSYHForm.setBanktype(loanEntity.getBankType());
		}
		CreditForm creditForm = new CreditForm();
		CreditReport creditReport = creditReportService.queryLoanapplyNo(zXSSYHForm.getReferId(),
				String.valueOf(StatusContexts.O2O_ZERO));
		if (creditReport != null) {
			// 查询配偶 征信信息
			CreditReport materCredit = creditReportService.queryLoanapplyNo(zXSSYHForm.getReferId(),
					String.valueOf(creditReport.getId()));
			if (materCredit != null) {
				CreditTransforCreditFrom.CreditTransToForm(creditForm, creditReport, materCredit);
				creditForm.setIds(materCredit.getId());
				creditForm.setParentIds(materCredit.getParentId());
			} else {
				CreditTransforCreditFrom.CreditTransToForm(creditForm, creditReport, null);
			}
		}
		ViewContext.put("loanEntity", loanEntity);
		ViewContext.put("userEntity", userEntity);
		ViewContext.put("creditForm", creditForm);
		ViewContext.put("zXSSYHForm", zXSSYHForm);
		return HtmlRestResult.html("workflowcheck/approval_zx_ajax");
	}

	/**
	 * 征信情况 动态表单编辑页面
	 * 
	 * @param zXSSYHForm
	 * @return
	 */
	@RequestMapping(value = "/workflowcheck/editZX")
	@TraceLoggerConfig(trackMaxTime=5000)
	public HtmlRestResult editZxView(ZXPTCWForm zXSSYHForm) {
		O2oLoanapplyEntity loanEntity = o2oLoanapplyService.findById(zXSSYHForm.getReferId());
		//1,借款人
		O2oLoanUserEntity userEntity = o2oLoanUserService.findById(loanEntity.getLoanId(), zXSSYHForm.getReferId());
		O2oZxEntity o2oZxEntity = o2oLoanapplyService.findO2oZxById(userEntity.getZxNo());
		
		//2,借款人配偶
		O2oLoanUserEntity userEntityS = o2oLoanUserService.findSpouseId(loanEntity.getLoanId(), zXSSYHForm.getReferId());
		O2oZxEntity o2oZxEntityS = null;
		if(userEntityS != null){
			o2oZxEntityS = o2oLoanapplyService.findO2oZxById(userEntityS.getZxNo());
		}
		
		CreditForm creditForm = new CreditForm();
		CreditReport creditReport = creditReportService.queryLoanapplyNo(zXSSYHForm.getReferId(),String.valueOf(StatusContexts.O2O_ZERO));
		if (creditReport != null) {
			CreditReport materCredit = creditReportService.queryLoanapplyNo(zXSSYHForm.getReferId(),String.valueOf(creditReport.getId()));
			if (materCredit != null) {
				CreditTransforCreditFrom.CreditTransToForm(creditForm, creditReport, materCredit);
				creditForm.setIds(materCredit.getId());
				creditForm.setParentIds(materCredit.getParentId());
			} else {
				CreditTransforCreditFrom.CreditTransToForm(creditForm, creditReport, null);
			}
		}else{
			if(BankRate.BANK_BC.equals(o2oZxEntity.getZxBank()) || BankRate.BANK_JCB.equals(o2oZxEntity.getZxBank())){
				logger.info("借款人请求征信报告：customerId[{}]", loanEntity.getLoanId());
				creditForm=zxResolveService.getZxInfo(loanEntity, loanEntity.getLoanId(), StatusContexts.ZX_CODE,creditForm , o2oZxEntity.getId(),false);
			}
			if(o2oZxEntityS!=null&&(BankRate.BANK_BC.equals(o2oZxEntityS.getZxBank()) || BankRate.BANK_JCB.equals(o2oZxEntityS.getZxBank()))){
				if(null!=userEntityS && null!=userEntityS.getLoanId()){
					logger.info("配偶请求征信报告：customerId[{}]", userEntityS.getLoanId());
					creditForm=zxResolveService.getZxInfo(loanEntity, userEntityS.getLoanId(), StatusContexts.ZX_CODE,creditForm ,o2oZxEntityS.getId() , true);
				}
			}

		}
		logger.info("返回征信情况实体creditForm:[{}]", creditForm.toString());
		ViewContext.put("loanEntity", loanEntity);
		ViewContext.put("userEntity", userEntity);
		ViewContext.put("userEntityS", userEntityS);
		ViewContext.put("creditForm", creditForm);
		ViewContext.put("zXSSYHForm", zXSSYHForm);
		return HtmlRestResult.popHtmlFragment("workflowcheck/edit_credit");
	}
	
	/**
	 * 征信财务表单 展示详情
	 * 
	 * @param zXPTCWForm
	 * @return
	 */
	@RequestMapping(value = "/workflowcheck/dk_view_zx", method = RequestMethod.GET)
	public HtmlRestResult ptcwView(ZXPTCWForm zXPTCWForm) {
		O2oLoanapplyEntity loanEntity = o2oLoanapplyService.findById(zXPTCWForm.getReferId());
		if (null != loanEntity) {
			SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
			zXPTCWForm = new ZXPTCWForm();
			zXPTCWForm.setLoanapplyno(loanEntity.getLoanapplyNo());
			zXPTCWForm.setReferId(loanEntity.getLoanapplyNo());
			if (null != loanEntity.getEaCooperationDate())
				zXPTCWForm.setEaTime(format.format(loanEntity.getEaCooperationDate()));
			zXPTCWForm.setEaStockNum(loanEntity.getEaStockNum());
			zXPTCWForm.setTakeAvgAmount(loanEntity.getEaPurchaseamount());
			zXPTCWForm.setArrearsAmountTotal(loanEntity.getEaStockBorrowing());
			zXPTCWForm.setCustomerSalesamount(loanEntity.getCustomerSalesamount());
		}
		ViewContext.put("loanEntity", loanEntity);
		ViewContext.put("zXPTCWForm", zXPTCWForm);
		return HtmlRestResult.html("workflowcheck/zx_ptcw_view");
	}
	/**
	 * 
	 * 内审 动态表单
	 * 
	 * @param loanapplyNo
	 * @return
	 */
	@RequestMapping("/workflowcheck/ns_zbfs_view")
	public HtmlRestResult output(ZXPTCWForm zXPTCWForm) {
		logger.info("内审动态表单，接收ZXPTCWForm：{}", zXPTCWForm.toString());
		O2oLoanapplyEntity loan = o2oLoanapplyService.findById(zXPTCWForm.getReferId());
		LoanapplyExpand expand = loanapplyExpandService.queryLoanapplyNo(zXPTCWForm.getReferId());
		loan.setPaymentType("LDZJ");
		ViewContext.put("loan", loan);
		ViewContext.put("expand", expand);
		ViewContext.put("nodeCode", zXPTCWForm.getNodeCode());
		
		
		if(StatusContexts.LOAN_TYPE_EA.equals(loan.getLoanType())){
			return HtmlRestResult.html("workflowcheck/ns_ea");
		}else if(StatusContexts.LOAN_TYPE_FQ.equals(loan.getLoanType())){
			return HtmlRestResult.html("workflowcheck/ns_fq");
		}else{
			queryDataList(zXPTCWForm.getReferId(), FileTypeConstants.DALIST_TYPE_DCWD, zXPTCWForm.getNodeCode());
			queryDataListNS(zXPTCWForm.getReferId(), FileTypeConstants.DALIST_TYPE_NSFJ, zXPTCWForm.getNodeCode());
			return HtmlRestResult.html("workflowcheck/ns_zbfs");
		}
	}
	
	
	   
	public void queryHouseDataList(String loanapplyNo) {
		PageResult<Object[]> pageResult = houseInfoService.findHouseListInfo(loanapplyNo,0,null);
		String[] oatitles = { "房产地址", "房产性质", "是否按揭", "估值方法", "信贷经理估值", "估值复核（万元）" };
		String o2ourl = "/house/house_list";
		o2ourl = UrlUtil.appendUrl(o2ourl, "loanapplyId", loanapplyNo);
		o2ourl = o2ourl + "&showPage=";
		PaginationInfo paginationInfo = new PaginationInfo(pageResult, oatitles, o2ourl);
		AjaxButton editButton = new AjaxButton("修改", "/house/ns_house_view?houseId=");
		Button[] detailButton = new Button[] { editButton};
		SelectDataOption[] selectDataOptions = {null,new SelectDataOption("CQXZ"),new SelectDataOption("SFAJ"),new SelectDataOption("GZFF"), null,null};
		paginationInfo.setSelectDataOptions(selectDataOptions);
		paginationInfo.setMoreButtons(detailButton);
		paginationInfo.setBuildPagingNavigation(false);
		paginationInfo.setFirstRenderColumnIndex(1);
		ViewContext.put("housePageResult", paginationInfo);
	}
	
	public void queryCarDataList(String loanapplyId) {
		PageResult<Object[]> pageResult = carInfoService.findCarListInfo(loanapplyId,0);
		String[] oatitles = { "品牌", "购入价值", "购入时间", "是否按揭","估值方法", "信贷经理估值", "估值复核（万元）" };
		String o2ourl = "/car/car_list";
		if (StringUtil.isNotBlank(loanapplyId)) {
			o2ourl = UrlUtil.appendUrl(o2ourl, "loanapplyId", loanapplyId);
			o2ourl = o2ourl + "&showPage=";
		} else {
			o2ourl = o2ourl + "?showPage=";
		}
		PaginationInfo paginationInfo = new PaginationInfo(pageResult, oatitles, o2ourl);
		AjaxButton editButton = new AjaxButton("修改", "/car/ns_car_view?carId=");
		Button[] detailButton = new Button[] { editButton};
		SelectDataOption[] selectDataOptions = {null,null,null,new SelectDataOption("SFAJ"),new SelectDataOption("CCGZFF"), null,null};
		paginationInfo.setSelectDataOptions(selectDataOptions);
		paginationInfo.setMoreButtons(detailButton);
		paginationInfo.setBuildPagingNavigation(false);
		paginationInfo.setFirstRenderColumnIndex(1);
		ViewContext.put("otherPageResult", paginationInfo);
	}
	
	public void queryOtherDataList(String loanapplyId) {
		PageResult<Object[]> pageResult = otherInfoService.findCarListInfo(loanapplyId,0);
		String[] oatitles = {"资产类型","信贷经理估值（万元）", "估值复核（万元）" };
		String o2ourl = "/other_assets/other_assets_list";
		if (StringUtil.isNotBlank(loanapplyId)) {
			o2ourl = UrlUtil.appendUrl(o2ourl, "loanapplyId", loanapplyId);
			o2ourl = o2ourl + "&showPage=";
		} else {
			o2ourl = o2ourl + "?showPage=";
		}
		PaginationInfo paginationInfo = new PaginationInfo(pageResult, oatitles, o2ourl);
		AjaxButton editButton = new AjaxButton("修改", "/other_assets/ns_other_view?otherId=");
		Button[] detailButton = new Button[] { editButton};
		SelectDataOption[] selectDataOptions = {new SelectDataOption("ZCLX"), null,null, null};
		paginationInfo.setSelectDataOptions(selectDataOptions);
		paginationInfo.setMoreButtons(detailButton);
		paginationInfo.setBuildPagingNavigation(false);
		paginationInfo.setFirstRenderColumnIndex(1);
		ViewContext.put("pageResult", paginationInfo);
	}
	/**
	 * 内审附件列表
	 * @param loanapplyNo
	 * @return
	 */
	@RequestMapping("/workflowcheck/ns_ea")
	public HtmlRestResult showDatalist(String loanapplyNo, String nodeCode){
		queryDataList(loanapplyNo, FileTypeConstants.DALIST_TYPE_CONTRACT, null);
		O2oLoanapplyEntity loanapply = o2oLoanapplyService.findById(loanapplyNo);
		ViewContext.put("loanapplyNo", loanapplyNo);
		ViewContext.put("nodeCode", nodeCode);
		ViewContext.put("loanId", loanapply.getLoanId());
		return HtmlRestResult.html("workflowcheck/ns_datalist");
	}
	/**
	 * 内审总部初审  表单
	 * @param loanapplyNo
	 * @return
	 */
	@RequestMapping("/workflowcheck/ns_zbcs")
	public HtmlRestResult updateNS(ZXPTCWForm zXPTCWForm){
		O2oLoanapplyEntity loanapply = o2oLoanapplyService.findById(zXPTCWForm.getReferId());
		ViewContext.put("loanapply", loanapply);
		return HtmlRestResult.html("workflowcheck/ns_zbcs");
	}

	/**
	 * 显示客户银行卡信息
	 * 
	 * @param zXPTCWForm
	 * @return
	 */
	@RequestMapping("/workflowcheck/interview_user_bank_view")
	public HtmlRestResult interviewNo(O2oBankInfoForm o2oBankInfoForm) {
		O2oBankInfoEntity o2oBankInfoEntity = new O2oBankInfoEntity();
		o2oBankInfoEntity.setLoanapplyNo(o2oBankInfoForm.getReferId());
		o2oBankInfoForm = o2oLoanapplyService.findO2oBankInfoEntity(o2oBankInfoForm.getReferId());
		ViewContext.put("o2oBankInfoEntity", o2oBankInfoForm);
		return HtmlRestResult.html("workflowcheck/contract_view");
	}
	
	/**
	 * 详情页显示保证金和管理费流程 平台财务表单
	 * 
	 * @param zXPTCWForm
	 * @return
	 */
	@RequestMapping("/workflowcheck/sqbzj_view")
	public HtmlRestResult feesView(ZXPTCWForm zXPTCWForm) {
		O2oLoanapplyEntity loan = o2oLoanapplyService.findById(zXPTCWForm.getReferId());
		LoanapplyExpand expand = loanapplyExpandService.queryLoanapplyNo(zXPTCWForm.getReferId());
		ViewContext.put("loan", loan);
		ViewContext.put("expand", expand);
		return HtmlRestResult.html("workflowcheck/sqbzj_ptcw_view");
	}

	/**
	 * 收取保证金和管理费流程 平台财务表单
	 * 
	 * @param zXPTCWForm
	 * @return
	 */
	@RequestMapping("/workflowcheck/sqbzj_ptcw_view")
	public HtmlRestResult fees(ZXPTCWForm zXPTCWForm) {
		O2oLoanapplyEntity loan = o2oLoanapplyService.findById(zXPTCWForm.getReferId());
		ViewContext.put("loanapply", loan);
		return HtmlRestResult.html("workflowcheck/sqbzj_ptcw");
	}
	/**
	 * 收取保证金和管理费流程 平台财务表单
	 * 
	 * @param zXPTCWForm
	 * @return
	 */
	@RequestMapping("/workflowcheck/sqbzj_ptcw_view1")
	public HtmlRestResult fees1(ZXPTCWForm zXPTCWForm) {
		O2oLoanapplyEntity loan = o2oLoanapplyService.findById(zXPTCWForm.getReferId());
		ViewContext.put("loanapply", loan);
		return HtmlRestResult.html("workflowcheck/sqbzj_ptcw1");
	}
	/**
	 * 收取保证金和管理费流程 ajax加载
	 * @param zXPTCWForm
	 * @return
	 */
//	@RequestMapping("/workflowcheck/sqbzj_ptcw_ajax")
//	public HtmlRestResult sqbzjAjax(ZXPTCWForm zXPTCWForm) {
//		logger.info("收取保证金和管理费流程，平台财务表单接收ZXPTCWForm：", zXPTCWForm.toString());
//		O2oLoanapplyEntity loan = o2oLoanapplyService.findById(zXPTCWForm.getReferId());
//		LoanapplyExpand expand = loanapplyExpandService.queryLoanapplyNo(zXPTCWForm.getReferId());
//		LoanapplyExpandDetail loanapplyExpandDetail=loanapplyExpandDetailService.queryDetail(expand.getId());
//		O2oLoanUserEntity loanUser=o2oLoanUserService.findById(loan.getLoanId(), loan.getLoanapplyNo());
//		logger.info("借款人身份证：[{}],查询新老系统可以划拨单号:[{}]",loanUser.getDocumentNo(),loan.getBillCode());
//		List<OaDeposit> billCodeList=tranDepositSevice.findBillCode(loanUser.getDocumentNo(),loan);
//		BzjPtcwForm bf=new BzjPtcwForm();
//		if(((expand.getRecDeposite().subtract(NullToZero(expand.getRedDeposite()))).add(NullToZero(expand.getRetaDeposite()))).compareTo(BigDecimal.ZERO)==-1){
//			bf.setPaidDeposit(BigDecimal.ZERO);
//		}else{
//			bf.setPaidDeposit((expand.getRecDeposite().subtract(NullToZero(expand.getRedDeposite())).add(NullToZero(expand.getRetaDeposite()))));	
//		}
//		if(((expand.getRecManger().subtract(NullToZero(expand.getRedManger()))).add(NullToZero(expand.getRedManger()))).compareTo(BigDecimal.ZERO)==-1){
//			bf.setPaidManger(BigDecimal.ZERO);
//		}else{
//			bf.setPaidManger((expand.getRecManger().subtract(NullToZero(expand.getRedManger()))).add(NullToZero(expand.getRedManger())));
//		}
//		if(((expand.getRecRisk().subtract(NullToZero(expand.getRedRisk()))).add(NullToZero(expand.getRedRisk()))).compareTo(BigDecimal.ZERO)==-1){
//			bf.setPaidRisk(BigDecimal.ZERO);
//		}else{
//			bf.setPaidRisk(expand.getRecRisk().subtract(NullToZero(expand.getRedRisk())).add(NullToZero(expand.getRedRisk())));
//		}
//		if(loanapplyExpandDetail!=null){
//			expand.setPaidDeposite(loanapplyExpandDetail.getPaidDeposite());
//			expand.setPaidManger(loanapplyExpandDetail.getPaidManger());
//			expand.setPaidRisk(loanapplyExpandDetail.getPaidRisk());
//			expand.setPayName(loanapplyExpandDetail.getPayName());
//			expand.setPayRemark(loanapplyExpandDetail.getPayRemark());
//			expand.setSubmitDate(loanapplyExpandDetail.getSubmitDate());
//			expand.setReceiveDeposit(loanapplyExpandDetail.getReceiveDeposit());
//			expand.setTransferDeposit(loanapplyExpandDetail.getTransferDeposit());
//			expand.setTransferNum(loanapplyExpandDetail.getTransferNum());
//		}else{
//			expand.setPaidDeposite(bf.getPaidDeposit());
//		}
//		ViewContext.put("loanapplyExpandDetail", loanapplyExpandDetail);
//		ViewContext.put("loan", loan);
//		ViewContext.put("billCodeList", billCodeList);
//		ViewContext.put("expand", expand);
//		ViewContext.put("ptcw", bf);
//		return HtmlRestResult.html("workflowcheck/sqbzj_ptcw_ajax");
//	}
	/**
	 * 收取保证金和管理费流程 ajax加载
	 * @param zXPTCWForm
	 * @return
	 */
	@RequestMapping("/workflowcheck/sqbzj_ptcw_ajax")
	public HtmlRestResult sqbzjAjax(ZXPTCWForm zXPTCWForm) {
		logger.info("收取保证金和管理费流程，平台财务表单接收ZXPTCWForm：[{}]", zXPTCWForm.toString());
		O2oLoanapplyEntity loan = o2oLoanapplyService.findById(zXPTCWForm.getReferId());
		LoanapplyExpand expand = loanapplyExpandService.queryLoanapplyNo(zXPTCWForm.getReferId());
		LoanapplyExpandDetail loanapplyExpandDetail=loanapplyExpandDetailService.queryDetail(expand.getId());
		O2oLoanUserEntity loanUser=o2oLoanUserService.findById(loan.getLoanId(), loan.getLoanapplyNo());
		List<OaDeposit> billCodeList=tranDepositSevice.findBillCode(loanUser.getDocumentNo(),loan);
		if(((expand.getRecDeposite().subtract(NullToZero(expand.getRedDeposite()))).add(NullToZero(expand.getRetaDeposite()))).compareTo(BigDecimal.ZERO)==-1){
			expand.setPaidDeposite(BigDecimal.ZERO);
		}else{
			expand.setPaidDeposite((expand.getRecDeposite().subtract(NullToZero(expand.getRedDeposite())).add(NullToZero(expand.getRetaDeposite()))));	
		}
		if(((expand.getRecManger().subtract(NullToZero(expand.getRedManger()))).add(NullToZero(expand.getRedManger()))).compareTo(BigDecimal.ZERO)==-1){
			expand.setPaidManger(BigDecimal.ZERO);
		}else{
			expand.setPaidManger((expand.getRecManger().subtract(NullToZero(expand.getRedManger()))).add(NullToZero(expand.getRedManger())));
		}
		if(((expand.getRecRisk().subtract(NullToZero(expand.getRedRisk()))).add(NullToZero(expand.getRedRisk()))).compareTo(BigDecimal.ZERO)==-1){
			expand.setPaidRisk(BigDecimal.ZERO);
		}else{
			expand.setPaidRisk(expand.getRecRisk().subtract(NullToZero(expand.getRedRisk())).add(NullToZero(expand.getRedRisk())));
		}
		if(loanapplyExpandDetail!=null){
			expand.setPaidDeposite(loanapplyExpandDetail.getPaidDeposite());
			expand.setPaidManger(loanapplyExpandDetail.getPaidManger());
			expand.setPaidRisk(loanapplyExpandDetail.getPaidRisk());
			expand.setPayName(loanapplyExpandDetail.getPayName());
			expand.setPayRemark(loanapplyExpandDetail.getPayRemark());
			expand.setSubmitDate(loanapplyExpandDetail.getSubmitDate());
			expand.setReceiveDeposit(loanapplyExpandDetail.getReceiveDeposit());
			expand.setTransferDeposit(loanapplyExpandDetail.getTransferDeposit());
			expand.setTransferNum(loanapplyExpandDetail.getTransferNum());
		}
		ViewContext.put("loanapplyExpandDetail", loanapplyExpandDetail);
		ViewContext.put("loan", loan);
		ViewContext.put("billCodeList", billCodeList);
		ViewContext.put("expand", expand);
		return HtmlRestResult.html("workflowcheck/sqbzj_ptcw_ajax");
	}
	/**
	 * 收取保证金和管理费流程 资金查账表单
	 * 
	 * @param zXPTCWForm
	 * @return
	 */
//	@RequestMapping("/workflowcheck/sqbzj_zjcz_view")
//	public HtmlRestResult order(ZXPTCWForm zXPTCWForm) {
//		O2oLoanapplyEntity loan = o2oLoanapplyService.findById(zXPTCWForm.getReferId());
//		LoanapplyExpand loanapplyExpand = loanapplyExpandService.queryLoanapplyNo(zXPTCWForm.getReferId());
//		LoanapplyExpandDetail loanapplyExpandDetail=loanapplyExpandDetailService.queryDetail(loanapplyExpand.getId());
//		List<String> transferList=new ArrayList<String>();
//		if(loanapplyExpandDetail!=null){
//			loanapplyExpand.setPaidDeposite(loanapplyExpandDetail.getPaidDeposite());
//			loanapplyExpand.setPaidManger(loanapplyExpandDetail.getPaidManger());
//			loanapplyExpand.setPaidRisk(loanapplyExpandDetail.getPaidRisk());
//			loanapplyExpand.setReceiveDeposit(loanapplyExpandDetail.getReceiveDeposit());
//			loanapplyExpand.setRedDeposite(loanapplyExpandDetail.getRedDeposite());
//			loanapplyExpand.setRedManger(loanapplyExpandDetail.getRedManger());
//			loanapplyExpand.setRedRisk(loanapplyExpandDetail.getRedRisk());
//			loanapplyExpand.setRecManger(loanapplyExpandDetail.getPaidManger());
//			loanapplyExpand.setRecRisk(loanapplyExpandDetail.getPaidRisk());
//			loanapplyExpand.setTransferDeposit(loanapplyExpandDetail.getTransferDeposit());
//			loanapplyExpand.setTransferNum(loanapplyExpandDetail.getTransferNum());
//			loanapplyExpand.setPayDate(loanapplyExpandDetail.getPayDate());
//			if(loanapplyExpandDetail.getTransferNum()!=null){
//				if(loanapplyExpandDetail.getTransferNum().contains(",")){
//					String str[]=loanapplyExpandDetail.getTransferNum().split(",");
//					for (String string : str) {
//						transferList.add(string.toString());
//					}
//				}else{
//					transferList.add(loanapplyExpandDetail.getTransferNum());
//				}
//			}
//		}
//		if(loanapplyExpand.getPaidDeposite()==null){
//			loanapplyExpand.setPaidDeposite(loanapplyExpand.getReceiveDeposit());
//		}
//		ViewContext.put("loanapplyExpand", loanapplyExpand);
//		ViewContext.put("loan", loan);
//		ViewContext.put("transferList", transferList);
//		return HtmlRestResult.html("workflowcheck/sqbzj_zjcz");
//}
	/**
	 * 收取保证金和管理费流程 资金查账表单
	 * 
	 * @param zXPTCWForm
	 * @return
	 */
	@RequestMapping("/workflowcheck/sqbzj_zjcz_view")
	public HtmlRestResult order(ZXPTCWForm zXPTCWForm) {
		O2oLoanapplyEntity loan = o2oLoanapplyService.findById(zXPTCWForm.getReferId());
		LoanapplyExpand loanapplyExpand = loanapplyExpandService.queryLoanapplyNo(zXPTCWForm.getReferId());
		LoanapplyExpandDetail loanapplyExpandDetail=loanapplyExpandDetailService.queryDetail(loanapplyExpand.getId());
		queryDataListBzj(zXPTCWForm.getReferId(), FileTypeConstants.DALIST_TYPE_BZJDATA, FileTypeConstants.DALIST_TYPE_BZJDFPZ, "VIEW_");
		List<String> transferList=new ArrayList<String>();
		if(loanapplyExpandDetail!=null){
			loanapplyExpand.setPaidDeposite(loanapplyExpandDetail.getPaidDeposite());
			loanapplyExpand.setPaidManger(loanapplyExpandDetail.getPaidManger());
			loanapplyExpand.setPaidRisk(loanapplyExpandDetail.getPaidRisk());
			loanapplyExpand.setReceiveDeposit(loanapplyExpandDetail.getReceiveDeposit());
			loanapplyExpand.setRedDeposite(loanapplyExpandDetail.getRedDeposite());
			loanapplyExpand.setRedManger(loanapplyExpandDetail.getRedManger());
			loanapplyExpand.setRedRisk(loanapplyExpandDetail.getRedRisk());
			loanapplyExpand.setRecManger(loanapplyExpandDetail.getPaidManger());
			loanapplyExpand.setRecRisk(loanapplyExpandDetail.getPaidRisk());
			loanapplyExpand.setTransferDeposit(loanapplyExpandDetail.getTransferDeposit());
			loanapplyExpand.setTransferNum(loanapplyExpandDetail.getTransferNum());
			loanapplyExpand.setPayDate(loanapplyExpandDetail.getPayDate());
			if(loanapplyExpandDetail.getTransferNum()!=null){
				if(loanapplyExpandDetail.getTransferNum().contains(",")){
					String str[]=loanapplyExpandDetail.getTransferNum().split(",");
					for (String string : str) {
						transferList.add(string.toString());
					}
				}else{
					transferList.add(loanapplyExpandDetail.getTransferNum());
				}
			}
		}
		if(loanapplyExpand.getPaidDeposite()==null){
			loanapplyExpand.setPaidDeposite(loanapplyExpand.getReceiveDeposit());
		}
		ViewContext.put("loanapplyExpand", loanapplyExpand);
		ViewContext.put("loan", loan);
		ViewContext.put("transferList", transferList);
		getBankAccount();
		return HtmlRestResult.html("workflowcheck/sqbzj_zjcz");
	}
	
	public void getBankAccount() {
		List<String> bankcards = bankAccountService.getBankAccount();
		ViewContext.put("bankAccountList", bankcards);
	}
	
	/**
	 * @Description:
	 *               <p>
	 *               退保证金管理费资金部门付款节点动态表单展示 选择付款账号
	 *               </p>
	 * @author CXW
	 * @date 2017年8月25日 上午10:53:26
	 * @version V1.0
	 */
	@RequestMapping("/workflowcheck/tfbzj_zjfk_view")
	public HtmlRestResult tbzjZjbu(ZXPTCWForm zXPTCWForm){
		LoanapplyExpand loanapplyExpand = loanapplyExpandService.queryLoanapplyNo(zXPTCWForm.getReferId());
		ViewContext.put("loanapplyExpand", loanapplyExpand);
		getBankAccount();
		return HtmlRestResult.html("workflowcheck/tfbzj_zjfk");
	}
	
	
	/**
	 * @Description:
	 *               <p>
	 *               退费金部门付款节点动态表单展示 选择付款账号
	 *               </p>
	 * @author yy
	 * @date 2017年12月5日 上午10:53:26
	 * @version V1.0
	 */
	@RequestMapping("/workflowcheck/gezhtk_zijbmfk")
	public HtmlRestResult gezhtk_zijbmfk(ZXPTCWForm zXPTCWForm){
		O2oBackFeesEntity  o2oBackFees = o2oBackFeesService.queryById(zXPTCWForm.getReferId());
		ViewContext.put("o2oBackFees", o2oBackFees);
		getBankAccount();
		return HtmlRestResult.html("workflowcheck/gezhtk_zijbmfk");
	}

	
	
	
	

	/**
	 * ajax 刷新保证金 打款凭证附件
	 * 
	 * @param loanapplyNo
	 * @param code
	 * @return
	 */
	@RequestMapping("/workflowcheck/sqbzjfile")
	public HtmlRestResult querySQBZJFile(String loanapplyNo, String code) {
		queryDataListBzj(loanapplyNo, FileTypeConstants.DALIST_TYPE_BZJDATA, FileTypeConstants.DALIST_TYPE_BZJDFPZ, null);
		ViewContext.put("loanapplyNo", loanapplyNo);
		return HtmlRestResult.html("/workflowcheck/sqbzjfile");
	}

	/**
	 * 
	 * 
	 * @param zXPTCWForm
	 * @return
	 */
	@RequestMapping("/workflowcheck/tfbzj_zjcz_view")
	public HtmlRestResult tfbzj(ZXPTCWForm zXPTCWForm) {
		O2oLoanapplyEntity loan = o2oLoanapplyService.findById(zXPTCWForm.getReferId());
		O2OComBackFee o2OComBackFee = o2oComBankFeeService.queryEntity(loan.getLoanapplyNo(), StatusContexts.WFTYPE_STATUS_RUN);
		ViewContext.put("loan", loan);
		ViewContext.put("o2OComBackFee", o2OComBackFee);
		return HtmlRestResult.html("workflowcheck/tfbzj_zjcz");
	}
	
	/**
	 * 显示 申报动态表单
	 * 
	 * @param zXPTCWForm
	 * @return
	 */
	@RequestMapping("/workflowcheck/contract_isnert")
	public HtmlRestResult contract(O2oContractForm o2oContractForm) {
		O2oBankInfoForm o2oBankInfoForm = new O2oBankInfoForm();
		o2oBankInfoForm = o2oLoanapplyService.findO2oBankInfoEntity(o2oContractForm.getReferId());
		ViewContext.put("o2oBankInfoEntity", o2oBankInfoForm);
		return HtmlRestResult.html("workflowcheck/contract");
	}

	/**
	 * ajax 刷新合同附件
	 * 
	 * @param loanapplyNo
	 * @param code
	 * @return
	 */
	@RequestMapping("/workflowcheck/contractfile")
	public HtmlRestResult queryFile(String loanapplyNo, String code) {
		queryDataList(loanapplyNo, FileTypeConstants.DALIST_TYPE_CONTRACT,null);
		O2oLoanapplyEntity entity = o2oLoanapplyService.findById(loanapplyNo);
		ViewContext.put("loan", entity);
		return HtmlRestResult.html("/workflowcheck/contractfile");
	}

	/**
	 * 银行放款跳转
	 * 
	 * @param zXPTCWForm
	 * @return
	 */
	@RequestMapping("/workflowcheck/paymentButton")
	public HtmlRestResult showButton(ZXPTCWForm zXPTCWForm) {
		O2oLoanapplyEntity entity = o2oLoanapplyService.findById(zXPTCWForm.getReferId());
		O2oBankLoanData bankData = loanService.queryBillCode(entity.getBillCode());
		O2oLoanForm o2oForm=new O2oLoanForm();
		if(null!=bankData){
			if(bankData.getLoanDate()!=null){
				o2oForm.setLoanDate(DateUtils.formateStandTime(bankData.getLoanDate()));
			}
		}
		ViewContext.put("o2oForm", o2oForm);
		ViewContext.put("o2oloanapply", entity);
		ViewContext.put("bankData", bankData);
		queryDataList(zXPTCWForm.getReferId(), FileTypeConstants.DALIST_TYPE_BC_CONTRACT,"TYPE");
		return HtmlRestResult.html("workflowcheck/yhss_fk");
	}
	/**
	 * 中行附件接口发送按钮
	 * 
	 * @return
	 */
	@RequestMapping("/workflowcheck/bcfiletypeButton")
	public HtmlRestResult showButton(String loanapplyNo) {
		O2oLoanapplyEntity entity = o2oLoanapplyService.findById(loanapplyNo);
		ViewContext.put("o2oloanapply", entity);
		return new HtmlRestResult("workflowcheck/bc_file_type_but");
	}

	/**
	 * Ajax 申报 ---银行（放款/驳回 ）按钮
	 * 
	 * @param zXPTCWForm
	 * @return
	 */
	@RequestMapping("/workflowcheck/payment")
	public HtmlRestResult ajaxButton(ZXPTCWForm zXPTCWForm) {
		O2oLoanapplyEntity entity = o2oLoanapplyService.findById(zXPTCWForm.getReferId());
		O2oBankLoanData bankData = loanService.queryBillCode(entity.getBillCode());
		O2oLoanUserEntity loanUser = o2oLoanUserService.findById(entity.getLoanId(), zXPTCWForm.getReferId());
		ViewContext.put("o2oloanapply", entity);
		ViewContext.put("bankData", bankData);
		ViewContext.put("loanUser", loanUser);
		O2oPaymentsForm o2oPaymentsForm = new O2oPaymentsForm();
		o2oPaymentsForm.setBillCode(entity.getBillCode());
		o2oPaymentsForm.setPageSize(10);
		PageResult<Object[]> pageResult = o2oPaymentsService.paymentsList(o2oPaymentsForm);
		String[] titles = { "贷款单号", "借款人姓名", "借款人证件号", "还款期数", "应还款日期", "剩余本金", "应还本金", "应还利息", "本期应还款" };
		String pageUrl = "/payments/payments_list";
		PaginationInfo paginationInfo = new PaginationInfo(pageResult, titles, pageUrl + "&showPage=");
		paginationInfo.setBuildPagingNavigation(false);
		paginationInfo.setFirstRenderColumnIndex(1);
		AjaxConfirmButton[] dealButton = new AjaxConfirmButton[] {
				new AjaxConfirmButton("删除", "/paymentsRest/paymentsDel?payments_id=") };
		paginationInfo.setMoreButtons(dealButton);
		ViewContext.put("paginationInfo", paginationInfo);
		ViewContext.put("vo", o2oPaymentsForm);
		if (pageResult.getData().size() > 0) {
			ViewContext.put("upload", "upload");
		}
		return HtmlRestResult.html("workflowcheck/bankData");
	}

	/**
	 * 显示合同信息
	 * 
	 * @param zXPTCWForm
	 * @return
	 */
	@RequestMapping("/workflowcheck/contract_view")
	public HtmlRestResult contractView(O2oContractForm o2oContractForm) {
		o2oContractForm = o2oLoanapplyService.findO2oContractForm(o2oContractForm);
		ViewContext.put("o2oContractForm", o2oContractForm);
		return HtmlRestResult.html("workflowcheck/contract_view");
	}

	/**
	 * 根据referId显示银行审批按钮
	 * 
	 * @param referId
	 * @return
	 */
	@RequestMapping(value = "/workflowcheck/bank_status_button", method = RequestMethod.GET)
	public HtmlRestResult bankButton(ZXSSYHForm zXSSYHForm) {
		ViewContext.put("loanapplyNo", zXSSYHForm.getReferId());
		return HtmlRestResult.html("workflowcheck/bank_status_button");
	}

	/**
	 * 获取SD数据 插入数据库
	 * 
	 * @param customerSd
	 * @return
	 */
	public O2oSDEntity querySd(String customerSd, String loanapplyNo,String customerSdNo) {
		logger.info("SD数据 插入数据库：", "贷款单号：" + loanapplyNo);
		SimpleDateFormat dateFormater = new SimpleDateFormat("yyyy-MM");
		String data = "<requestxml><customerCode>" + customerSd + "</customerCode><cno>"+customerSdNo+"</cno><beginDate>"
				+ dateFormater.format(new Date()) + "</beginDate></requestxml>";
		O2oSDEntity sdEntity = new O2oSDEntity();
		try {
			Service service = new Service();
			Call call = (Call) service.createCall();
			call.setTimeout(new Integer(15000));
			call.setTargetEndpointAddress(sdUrl);
			call.setOperationName("getSDStoreSalesAndReceivedData");
			String s = (String) call.invoke(new String[] { data });
			logger.info("resp:", s);
			Document doc = DocumentHelper.parseText(s);
			Element root = doc.getRootElement().element("statisticsList");
			if (root != null) {
				@SuppressWarnings("unchecked")
				List<Element> list = root.elements();
				sdEntity.setLoanapplyNo(loanapplyNo);
				sdEntity.setCreateTime(new Date());
				sdEntity.setUpdateTime(new Date());
				for (int i = 0; i < list.size(); i++) {
					if (i == 0) {
						sdEntity.setFirstMonth(String.valueOf(list.get(0).element("statisticDate").getData()));
						sdEntity.setFirstTakeAmount(new BigDecimal(String.valueOf(
								!StringUtil.isNotBlank(list.get(0).element("salesMoney").getData().toString()) ? "0"
										: list.get(0).element("salesMoney").getData().toString())));
						sdEntity.setFirstPaymentAmount(new BigDecimal(String.valueOf(
								!StringUtil.isNotBlank(list.get(0).element("receivedMoney").getData().toString()) ? "0"
										: list.get(0).element("receivedMoney").getData())));
						sdEntity.setFirstRecAmount(
								sdEntity.getFirstTakeAmount().subtract(sdEntity.getFirstPaymentAmount()));
					}
					if (i == 1) {
						sdEntity.setSecondMonth(String.valueOf(list.get(1).element("statisticDate").getData()));
						sdEntity.setSecondTakeAmount(new BigDecimal(String
								.valueOf(!StringUtil.isNotBlank(list.get(1).element("salesMoney").getData().toString())
										? "0" : list.get(1).element("salesMoney").getData())));
						sdEntity.setSecondPaymentAmount(new BigDecimal(String.valueOf(
								!StringUtil.isNotBlank(list.get(1).element("receivedMoney").getData().toString()) ? "0"
										: list.get(1).element("receivedMoney").getData())));
						sdEntity.setSecondRecAmount(
								sdEntity.getSecondTakeAmount().subtract(sdEntity.getSecondPaymentAmount()));
					}
					if (i == 2) {
						sdEntity.setThirdMonth(String.valueOf(list.get(2).element("statisticDate").getData()));
						sdEntity.setThirdTakeAmount(new BigDecimal(String
								.valueOf(!StringUtil.isNotBlank(list.get(2).element("salesMoney").getData().toString())
										? "0" : list.get(2).element("salesMoney").getData())));
						sdEntity.setThirdPaymentAmount(new BigDecimal(String.valueOf(
								!StringUtil.isNotBlank(list.get(2).element("receivedMoney").getData().toString()) ? "0"
										: list.get(2).element("receivedMoney").getData())));
						sdEntity.setThirdRecAmount(
								sdEntity.getThirdTakeAmount().subtract(sdEntity.getThirdPaymentAmount()));
					}
					if (i == 3) {
						sdEntity.setFourthMonth(String.valueOf(list.get(3).element("statisticDate").getData()));
						sdEntity.setFourthTakeAmount(new BigDecimal(String
								.valueOf(!StringUtil.isNotBlank(list.get(3).element("salesMoney").getData().toString())
										? "0" : list.get(3).element("salesMoney").getData())));
						sdEntity.setFourthPaymentAmount(new BigDecimal(String.valueOf(
								!StringUtil.isNotBlank(list.get(3).element("receivedMoney").getData().toString()) ? "0"
										: list.get(3).element("receivedMoney").getData())));
						sdEntity.setFourthRecAmount(
								sdEntity.getFourthTakeAmount().subtract(sdEntity.getFourthPaymentAmount()));
					}
					if (i == 4) {
						sdEntity.setFifthMonth(String.valueOf(list.get(4).element("statisticDate").getData()));
						sdEntity.setFifthTakeAmount(new BigDecimal(String
								.valueOf(!StringUtil.isNotBlank(list.get(4).element("salesMoney").getData().toString())
										? "0" : list.get(4).element("salesMoney").getData())));
						sdEntity.setFifthPaymentAmount(new BigDecimal(String.valueOf(
								!StringUtil.isNotBlank(list.get(4).element("receivedMoney").getData().toString()) ? "0"
										: list.get(4).element("receivedMoney").getData())));
						sdEntity.setFifthRecAmount(
								sdEntity.getFifthTakeAmount().subtract(sdEntity.getFifthPaymentAmount()));
					}
					if (i == 5) {
						sdEntity.setSixthMonth(String.valueOf(list.get(5).element("statisticDate").getData()));
						sdEntity.setSixthTakeAmount(new BigDecimal(String
								.valueOf(!StringUtil.isNotBlank(list.get(5).element("salesMoney").getData().toString())
										? "0" : list.get(5).element("salesMoney").getData())));
						sdEntity.setSixthPaymentAmount(new BigDecimal(String.valueOf(
								!StringUtil.isNotBlank(list.get(5).element("receivedMoney").getData().toString()) ? "0"
										: list.get(5).element("receivedMoney").getData())));
						sdEntity.setSixRecAmount(
								sdEntity.getSixthTakeAmount().subtract(sdEntity.getSixthPaymentAmount()));
					}
					if (i == 6) {
						sdEntity.setTakeAvgAmount(new BigDecimal(String.valueOf(
								!StringUtil.isNotBlank(list.get(6).element("salesMoney").getData().toString()) ? "0"
										: list.get(6).element("salesMoney").getData().toString())));
						sdEntity.setPaymentAvgAmount(new BigDecimal(String.valueOf(
								!StringUtil.isNotBlank(list.get(6).element("receivedMoney").getData().toString()) ? "0"
										: list.get(6).element("receivedMoney").getData().toString())));
						sdEntity.setRecAvgAmount(sdEntity.getTakeAvgAmount().subtract(sdEntity.getPaymentAvgAmount()));
					}
				}
			} else {
				sdEntity.setCreateTime(new Date());
				sdEntity.setUpdateTime(new Date());
				sdEntity.setLoanapplyNo(loanapplyNo);
				sdEntity = initEmptySDEntity(sdEntity);// 构建为0的sdEntity对象
			}
			o2oSdService.saveSDEntity(sdEntity);
			if (sdEntity.getPaymentAvgAmount() != null || sdEntity.getTakeAvgAmount() != null) {
				SDForm sdForm = new SDForm();
				sdForm.setLoanapplyNo(loanapplyNo);
				sdForm.setPaymentAvgAmount(sdEntity.getPaymentAvgAmount());
				sdForm.setTakeAvgAmount(sdEntity.getTakeAvgAmount());
				o2oLoanapplyService.updatePTCW(sdForm);
			}
		} catch (Exception e) {
			sdEntity = initEmptySDEntity(sdEntity);// 构建为0的sdEntity对象
			o2oSdService.saveSDEntity(sdEntity);
			if (sdEntity.getPaymentAvgAmount() != null || sdEntity.getTakeAvgAmount() != null) {
				SDForm sdForm = new SDForm();
				sdForm.setLoanapplyNo(loanapplyNo);
				sdForm.setPaymentAvgAmount(sdEntity.getPaymentAvgAmount());
				sdForm.setTakeAvgAmount(sdEntity.getTakeAvgAmount());
				o2oLoanapplyService.updatePTCW(sdForm);
			}
		}
		return sdEntity;
	}

	public O2oSDEntity initEmptySDEntity(O2oSDEntity sdEntity) {
		for (int i = 0; i < ComConstants.SD_MONTHSIZE; i++) {
			Date date = DateUtils.add(new Date(), Calendar.MONTH, -i);
			String dateString = DateUtils.formateStandTime(date);
			dateString = dateString.substring(0, 7);
			if (i == 0) {
				sdEntity.setFirstMonth(dateString);
				sdEntity.setFirstTakeAmount(new BigDecimal(0));
				sdEntity.setFirstPaymentAmount(new BigDecimal(0));
				sdEntity.setFirstRecAmount(new BigDecimal(0));
			}
			if (i == 1) {
				sdEntity.setSecondMonth(dateString);
				sdEntity.setSecondTakeAmount(new BigDecimal(0));
				sdEntity.setSecondPaymentAmount(new BigDecimal(0));
				sdEntity.setSecondRecAmount(new BigDecimal(0));
			}
			if (i == 2) {
				sdEntity.setThirdMonth(dateString);
				sdEntity.setThirdTakeAmount(new BigDecimal(0));
				sdEntity.setThirdPaymentAmount(new BigDecimal(0));
				sdEntity.setThirdRecAmount(new BigDecimal(0));
			}
			if (i == 3) {
				sdEntity.setFourthMonth(dateString);
				sdEntity.setFourthTakeAmount(new BigDecimal(0));
				sdEntity.setFourthPaymentAmount(new BigDecimal(0));
				sdEntity.setFourthRecAmount(new BigDecimal(0));
			}
			if (i == 4) {
				sdEntity.setFifthMonth(dateString);
				sdEntity.setFifthTakeAmount(new BigDecimal(0));
				sdEntity.setFifthPaymentAmount(new BigDecimal(0));
				sdEntity.setFifthRecAmount(new BigDecimal(0));
			}
			if (i == 5) {
				sdEntity.setSixthMonth(dateString);
				sdEntity.setSixthTakeAmount(new BigDecimal(0));
				sdEntity.setSixthPaymentAmount(new BigDecimal(0));
				sdEntity.setSixRecAmount(new BigDecimal(0));
			}
			if (i == 6) {
				sdEntity.setTakeAvgAmount(new BigDecimal(0));
				sdEntity.setPaymentAvgAmount(new BigDecimal(0));
				sdEntity.setRecAvgAmount(new BigDecimal(0));
			}
		}
		return sdEntity;
	}

	public void queryDataListBzj(String loanapplyNo, String bzjdata, String bzjGlfDfpz, String type) {
		PageResult<Object[]> pageResult = o2oLoanapplyService.findO2oDataListEntityById(loanapplyNo, bzjdata, bzjGlfDfpz);
		String titles[] = { "附件类型", "文件名", "提交人", "提交时间", "更新时间" };
		Button[] titleButtons = new Button[] { null,
				ButtonHelper.createOpenButton(null, "/file/download?datalistno=") };
		PaginationInfo paginationInfo = new PaginationInfo(pageResult, titles);
		AjaxConfirmButton[] dealButton=null;
		if(type==null){
			dealButton = new AjaxConfirmButton[] { new AjaxConfirmButton("删除 ", "/loanrest/delete/") };
		} else if(type.equals("NS_XDJL")){
			dealButton = new AjaxConfirmButton[] { new AjaxConfirmButton("删除 ", "/loanrest/delete/") };
		}
		paginationInfo.setMoreButtons(dealButton);
		paginationInfo.setTitleButtons(titleButtons);
		paginationInfo.setBuildPagingNavigation(false);
		paginationInfo.setFirstRenderColumnIndex(1);
		paginationInfo.setBuildRowNumber(true);
		ViewContext.put("pageResult", paginationInfo);// 个人附件
	}
	
	public void queryDataList(String loanapplyNo, String code,String type) {
		PageResult<Object[]> pageResult = o2oLoanapplyService.findO2oDataListEntityById(loanapplyNo, "'" + code + "'");
		String titles[] = { "附件类型", "文件名", "提交人", "提交时间", "更新时间" };
		Button[] titleButtons = new Button[] { null,
				ButtonHelper.createOpenButton(null, "/file/download?datalistno=") };
		PaginationInfo paginationInfo = new PaginationInfo(pageResult, titles);
		AjaxConfirmButton[] dealButton=null;
		if(type==null){
			dealButton = new AjaxConfirmButton[] { new AjaxConfirmButton("删除 ", "/loanrest/delete/") };
		} else if(type.equals("NS_XDJL")){
			dealButton = new AjaxConfirmButton[] { new AjaxConfirmButton("删除 ", "/loanrest/delete/") };
		}
		paginationInfo.setMoreButtons(dealButton);
		paginationInfo.setTitleButtons(titleButtons);
		paginationInfo.setBuildPagingNavigation(false);
		paginationInfo.setFirstRenderColumnIndex(1);
		paginationInfo.setBuildRowNumber(true);
		ViewContext.put("pageResult", paginationInfo);// 个人附件
	}

	public void queryDataListNS(String loanapplyNo, String code,String type) {
		PageResult<Object[]> pageResult = o2oLoanapplyService.findO2oDataListEntityById(loanapplyNo, "'" + code + "'");
		String titles[] = { "附件类型", "文件名", "提交人", "提交时间", "更新时间" };
		Button[] titleButtons = new Button[] { null,
				ButtonHelper.createOpenButton(null, "/file/download?datalistno=") };
		PaginationInfo paginationInfo = new PaginationInfo(pageResult, titles);
		AjaxConfirmButton[] dealButton=null;
		if(type==null){
			dealButton = new AjaxConfirmButton[] { new AjaxConfirmButton("删除 ", "/loanrest/delete/") };
		} else if(type.equals("NS_XDJL")){
			dealButton = new AjaxConfirmButton[] { new AjaxConfirmButton("删除 ", "/loanrest/delete/") };
		}
		paginationInfo.setMoreButtons(dealButton);
		paginationInfo.setTitleButtons(titleButtons);
		paginationInfo.setBuildPagingNavigation(false);
		paginationInfo.setFirstRenderColumnIndex(1);
		paginationInfo.setBuildRowNumber(true);
		ViewContext.put("pageResultNS", paginationInfo);// 个人附件
	}
	
	/**
	 * 显示退费信息
	 * 
	 * @param zXPTCWForm
	 * @return
	 */
	@RequestMapping("/workflowcheck/backfee_view")
	public HtmlRestResult backFeeView(ComBackFeeWorkForm comBackFeeWorkForm) {
		O2OComBackFee o2OComBackFee = o2OComBankFeeService.queryEntity(comBackFeeWorkForm.getReferId(),
				StatusContexts.WFTYPE_STATUS_RUN);
		LoanapplyExpand loanapplyExpand = loanapplyExpandService.queryLoanapplyNo(comBackFeeWorkForm.getReferId());
		if (StatusContexts.DATA_SOURCE_OLD.equals(o2OComBackFee.getDataSource())) {
			loanapplyExpand = new LoanapplyExpand();
			OaBackFeeEntity oaBackFeeEntity = o2OComBankFeeService.findOaBackFee(o2OComBackFee.getBillCode());
			loanapplyExpand.setRecDeposite(oaBackFeeEntity.getReceivableBond());
			loanapplyExpand.setRedDeposite(oaBackFeeEntity.getNetReceiptsBond());
			loanapplyExpand.setRetaDeposite(oaBackFeeEntity.getRetiredBond());
			loanapplyExpand.setRetnDeposite(oaBackFeeEntity.getNotRetreatBond());
			loanapplyExpand.setRecManger(oaBackFeeEntity.getReceivableFee());
			loanapplyExpand.setRedManger(oaBackFeeEntity.getNetReceiptsFee());
			loanapplyExpand.setRetaManage(oaBackFeeEntity.getRetiredFee());
			loanapplyExpand.setRetnManage(oaBackFeeEntity.getNotRetreatFee());
			loanapplyExpand.setRecRisk(oaBackFeeEntity.getReceivableRisk());
			loanapplyExpand.setRedRisk(oaBackFeeEntity.getNetReceiptsRisk());
			loanapplyExpand.setRetaRisk(oaBackFeeEntity.getRetiredRisk());
			loanapplyExpand.setRetnRisk(oaBackFeeEntity.getNotRetreatRisk());
		}
		ViewContext.put("loanapplyExpand", loanapplyExpand);
		ViewContext.put("o2OComBackFee", o2OComBackFee);
		return HtmlRestResult.html("workflowcheck/backfee_view");
	}
	
	/**
	 * 显示退费信息
	 * 
	 * @param zXPTCWForm
	 * @return
	 */
	@RequestMapping("/workflowcheck/backfee_view_edit")
	public HtmlRestResult backFeeViewEdit(ComBackFeeWorkForm comBackFeeWorkForm) {
		O2OComBackFee o2OComBackFee = o2OComBankFeeService.queryEntity(comBackFeeWorkForm.getReferId(),
				StatusContexts.WFTYPE_STATUS_RUN);
		LoanapplyExpand loanapplyExpand = loanapplyExpandService.queryLoanapplyNo(comBackFeeWorkForm.getReferId());
		if (StatusContexts.DATA_SOURCE_OLD.equals(o2OComBackFee.getDataSource())) {
			loanapplyExpand = new LoanapplyExpand();
			OaBackFeeEntity oaBackFeeEntity = o2OComBankFeeService.findOaBackFee(o2OComBackFee.getBillCode());
			loanapplyExpand.setRecDeposite(oaBackFeeEntity.getReceivableBond());
			loanapplyExpand.setRedDeposite(oaBackFeeEntity.getNetReceiptsBond());
			loanapplyExpand.setRetaDeposite(oaBackFeeEntity.getRetiredBond());
			loanapplyExpand.setRetnDeposite(oaBackFeeEntity.getNotRetreatBond());
			loanapplyExpand.setRecManger(oaBackFeeEntity.getReceivableFee());
			loanapplyExpand.setRedManger(oaBackFeeEntity.getNetReceiptsFee());
			loanapplyExpand.setRetaManage(oaBackFeeEntity.getRetiredFee());
			loanapplyExpand.setRetnManage(oaBackFeeEntity.getNotRetreatFee());
			loanapplyExpand.setRecRisk(oaBackFeeEntity.getReceivableRisk());
			loanapplyExpand.setRedRisk(oaBackFeeEntity.getNetReceiptsRisk());
			loanapplyExpand.setRetaRisk(oaBackFeeEntity.getRetiredRisk());
			loanapplyExpand.setRetnRisk(oaBackFeeEntity.getNotRetreatRisk());
		}
		List<String> payTypeList = Arrays.asList(o2OComBackFee.getPayType().split(","));
		ViewContext.put("payTypeList",payTypeList);
		ViewContext.put("loanapplyExpand", loanapplyExpand);
		ViewContext.put("o2OComBackFee", o2OComBackFee);
		return HtmlRestResult.html("workflowcheck/backfee_view_edit");
	}
	
	/**
	 * 退费资金部节点   生成打印退款信息单
	 * @param comBackFeeWorkForm
	 * @return
	 */
	@RequestMapping("/workflowcheck/rbackprint")
	public HtmlRestResult rbackfeePrint(ComBackFeeWorkForm comBackFeeWorkForm) {
		O2OComBackFee backFee  =o2OComBankFeeService.queryEntity(comBackFeeWorkForm.getReferId(),
				StatusContexts.WFTYPE_STATUS_RUN);;
		ViewContext.put("comBackFee", backFee);
		return HtmlRestResult.html("workflowcheck/rbackfeePrint");
	}
	
	/**
	 * 个人账户退款 总部财务初审 资金部节点   生成打印退款信息单
	 * @param comBackFeeWorkForm
	 * @return
	 */
	@RequestMapping("/workflowcheck/rbacksprint")
	public HtmlRestResult rbacksprint(ComBackFeeWorkForm comBackFeeWorkForm) {
		
		O2oBackFeesEntity  entity = o2oBackFeesService.queryById(comBackFeeWorkForm.getReferId());
		ViewContext.put("o2oBackFees", entity);
		return HtmlRestResult.html("workflowcheck/rbackfeesPrint");
	}
	
	
	/**
	 * 银行申报审查
	 * 
	 * @param zXPTCWForm
	 * @return
	 */
	@RequestMapping("/workflowcheck/bankLoanData")
	public HtmlRestResult bankLoanData(MQZBSBYHFrom mQZBSBYHFrom) {
		logger.info("银行申报审查动态表单VO:[{}]",mQZBSBYHFrom.toString());
		O2oLoanapplyEntity entity = o2oLoanapplyService.findById(mQZBSBYHFrom.getReferId());
		int count=o2oLoanapplyService.otherLoanapplyCount(entity.getLoanapplyNo(),entity.getLoanId());
		if(count>0){
			logger.info("单号:[{}],有代偿记录,修改主表代偿状态",mQZBSBYHFrom.getReferId());
			o2oLoanapplyService.updateDcFlag(entity.getLoanapplyNo(),StatusContexts.O2O_YES);
		}else{
			o2oLoanapplyService.updateDcFlag(entity.getLoanapplyNo(),StatusContexts.O2O_NO);
		}
		O2oLoanapplyEntity loanapply = o2oLoanapplyService.findById(entity.getLoanapplyNo());
		queryDataList(mQZBSBYHFrom.getReferId(), FileTypeConstants.DALIST_TYPE_BC_CONTRACT,null);
		ViewContext.put("loanapply", loanapply);
		mQZBSBYHFrom.setIsCheckMqCl(entity.getIsCheckMqCl());
		mQZBSBYHFrom.setIsPhoneCheck(entity.getIsPhoneCheck());
		mQZBSBYHFrom.setPhoneCheckMessage(entity.getPhoneCheckMessage());
		ViewContext.put("mQZBSBYHFrom", mQZBSBYHFrom);
		return HtmlRestResult.html("workflowcheck/bankloanData");
	}
	/**
	 * 银行审查  代偿列表展示页面
	 * @param mQZBSBYHFrom
	 * @return
	 */
	@RequestMapping("/workflowcheck/otherLoanapply")
	public HtmlRestResult otherLoanapply(MQZBSBYHFrom mQZBSBYHFrom) {
		logger.info("AJAX加载系统借款人和配偶是否逾期和代偿信息:VO[{}]",mQZBSBYHFrom.toString());
		List<Object> billCodes=o2oLoanapplyService.findLoanIds(mQZBSBYHFrom.getReferId(), mQZBSBYHFrom.getLoanId());
		PageResult<Object[]> result=oaloanapplyDetailService.queryOverList(billCodes);
		String title2[] = { "贷款单号", "逾期本金", "逾期利息", "类型", "罚息合计", "拖欠总额", "处置金额", "处置时间" };
		Button[] titleButtons2 = new Button[] { ButtonHelper.createOpenButton(null, "/detail?billCode=") };
		PaginationInfo auditInfo2 = new PaginationInfo(result, title2, null);
		auditInfo2.setFormats(new Format[] { null, new DecimalFormat(",##0.00"), new DecimalFormat(",##0.00"),null,new DecimalFormat(",##0.00"), new DecimalFormat(",##0.00"), new DecimalFormat(",##0.00"), null });
		auditInfo2.setBuildPagingNavigation(false);
		auditInfo2.setFirstRenderColumnIndex(0);
		auditInfo2.setBuildRowNumber(true);
		auditInfo2.setTitleButtons(titleButtons2);
		ViewContext.put("oaSize", result.getReturnDataSize());
		ViewContext.put("oaOverdueInfo", auditInfo2);
		return HtmlRestResult.html("workflowcheck/otherloanapply");
	}
	/**
	 * BigDecimal 为空值转成0
	 * @param decimal
	 * @return
	 */
	public BigDecimal NullToZero(BigDecimal decimal){
		if(decimal==null){
			decimal=BigDecimal.ZERO;
		}
		return decimal;
	}
	
	/**
	 * 
	 * 品牌贷款内审 动态表单
	 * 
	 * @param loanapplyNo
	 * @return
	 */
	@RequestMapping("/workflowcheck/ns_zbfs_view_bp")
	public HtmlRestResult outputbp(ZXPTCWForm zXPTCWForm) {
		logger.info("内审动态表单，接收ZXPTCWForm：{}", zXPTCWForm.toString());
		O2oLoanapplyEntity loan = o2oLoanapplyService.findById(zXPTCWForm.getReferId());
		LoanapplyExpand expand = loanapplyExpandService.queryLoanapplyNo(zXPTCWForm.getReferId());
		loan.setPaymentType("LDZJ");
		ViewContext.put("loan", loan);
		ViewContext.put("expand", expand);
		ViewContext.put("nodeCode", zXPTCWForm.getNodeCode());
		return HtmlRestResult.html("workflowcheck/bp/ns_zbfs_pb");
	}
	
	/**
	 * 征品牌贷款 信动态表单---平台财务
	 * 
	 * @param zXPTCWForm
	 * @return
	 */
	@RequestMapping(value = "/workflowcheck/zx_ptcw_view_pb", method = RequestMethod.GET)
	public HtmlRestResult ptcwpb(ZXPTCWForm zXPTCWForm) {
		logger.info("征信平台财务接收zXPTCWForm：", zXPTCWForm.toString());
		ViewContext.put("zXPTCWForm", zXPTCWForm);
		return HtmlRestResult.html("workflowcheck/zx_ptcw_pb");
	}
	
	
	
	
	/**
	 * 特殊面签申报动态表单
	 * 
	 * @param referId
	 * @return
	 */
	@RequestMapping(value = "/workflowcheck/tsmqsb_view", method = RequestMethod.GET)
	public HtmlRestResult tsmqsb(MQZBSBYHFrom mQZBSBYHFrom) {
		O2OSpecialInterview specialInterview =  o2OSpecialInterviewService.queryEntity(mQZBSBYHFrom.getReferId()); // 特殊面签申报实体类
		if(specialInterview!=null){
			mQZBSBYHFrom.setPhoneCheckMessage(specialInterview.getSpecialReasons());
		}
		O2oLoanapplyEntity loan = o2oLoanapplyService.findById(mQZBSBYHFrom.getReferId());
		O2oLoanUserEntity loanUser = o2oLoanapplyService.findLoanUserEntity(mQZBSBYHFrom.getReferId(), loan.getLoanId());
		O2oLoanUserEntity materEntity = o2oLoanUserService.findSpouseId(loan.getLoanId(), loan.getLoanapplyNo());
		ViewContext.put("loanUser", loanUser);
		ViewContext.put("materEntity", materEntity);
		ViewContext.put("mQZBSBYHFrom", mQZBSBYHFrom);
		return HtmlRestResult.html("workflowcheck/tsmqsb_view");
	}

	
	/**
	 * 特殊面签申报动态表单
	 * 
	 * @param referId
	 * @return
	 */
	@RequestMapping(value = "/workflowcheck/tsmqsb_flow_detail", method = RequestMethod.GET)
	public HtmlRestResult tsmqsb_flow_detail(MQZBSBYHFrom mQZBSBYHFrom) {
		O2OSpecialInterview specialInterview =  o2OSpecialInterviewService.queryEntity(mQZBSBYHFrom.getReferId()); // 特殊面签申报实体类
		if(specialInterview!=null){
			mQZBSBYHFrom.setPhoneCheckMessage(specialInterview.getSpecialReasons());
		}
		O2oLoanapplyEntity loan = o2oLoanapplyService.findById(mQZBSBYHFrom.getReferId());
		O2oLoanUserEntity loanUser = o2oLoanapplyService.findLoanUserEntity(mQZBSBYHFrom.getReferId(), loan.getLoanId());
		O2oLoanUserEntity materEntity = o2oLoanUserService.findSpouseId(loan.getLoanId(), loan.getLoanapplyNo());
		ViewContext.put("loanUser", loanUser);
		ViewContext.put("materEntity", materEntity);
		ViewContext.put("mQZBSBYHFrom", mQZBSBYHFrom);
		ViewContext.put("specialInterview", specialInterview);
		return HtmlRestResult.html("workflowcheck/tsmqsb_flow_detail");
	}
	

	/**
	 * @Title: fkzz
	 * @Description: 付款转账
	 * @author 张庆奇
	 * @param vo
	 * @return
	 * @return HtmlRestResult
	 * @throws
	 * @date 2017年5月18日 上午11:40:11
	 */
	@RequestMapping(value = "/workflowcheck/fkzz_view", method = RequestMethod.GET)
	public HtmlRestResult fkzz(O2oTransferAccountVo vo) {
		logger.info("访问付款动态表单开始，贷款单号为：【{}】", vo.getId());
		O2oTransferAccount transferAccount=o2oTransferAccountService.findById(vo.getId());
		ViewContext.put("vo", transferAccount);
		
		return HtmlRestResult.html("workflowcheck/fkzz_view");
	}
	
	
	
	/**
	 * @Title: collectFees_view
	 * @Description: 个人账户打款动态表单
	 * @author 张庆奇
	 * @param vo
	 * @return
	 * @return HtmlRestResult
	 * @throws
	 * @date 2017年12月5日 上午11:26:24
	 */
	@RequestMapping(value = "/workflowcheck/collectFees_view", method = RequestMethod.GET)
	public HtmlRestResult collectFees_view(O2oCollectFeesVo vo) {
		logger.info("访问个人账户动态表单开始，贷单号为：【{}】", vo.getReferId());
		O2oCollectFee entity = o2oCollectFeesService.queryById(vo.getReferId());
		ViewContext.put("entity", entity);
		getBankAccount();
		return HtmlRestResult.html("workflowcheck/collectFees_view");
	}
	
}
